package com.atguigu.lease.web.admin.custom.converter;


import com.atguigu.lease.model.enums.ItemType;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * 自定义转换器，string to 标签类型
 */
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String code) {

        //取得 枚举类中所有对象
        ItemType[] values = ItemType.values();
        //遍历数组若匹配直接返回
        for (ItemType value:values) {
            if(value.getCode().equals(Integer.valueOf(code))){
                return value;
            }
        }

        throw new IllegalArgumentException("参数不存在");
    }
}
